home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AOL File Library: 2,801 to 2,900
/
aol-file-protocol-4400-2801-to-2900.zip
/
AOLDLs
/
C++ Files Library
/
Acere (Card Game)
/
AcereÄ.sit
/
Acereƒ
/
WellFreeCell.cp
< prev
next >
Wrap
Text File
|
1994-08-25
|
6KB
|
234 lines
// ===========================================================================
// WellFreeCell.cp ⌐1993 Metrowerks Inc. All rights reserved.
// ===========================================================================
//
// Class for an object that can draw itself and respond to mouse clicks
#ifdef PowerPlant_PCH
#include PowerPlant_PCH
#endif
#include "WellFreeCell.h"
#include "CardDeck.h"
#include "AcereApp.h"
#include "CTextDoc.h"
#include <LView.h>
#include <LStream.h>
#include <PP_Messages.h>
#include <UDrawingState.h>
extern CTextDoc *theDoc;
// ---------------------------------------------------------------------------
// Ñ CreatePaneStream [static]
// ---------------------------------------------------------------------------
// Return a new Pane object initialized using data from a Stream
WellFreeCell*
WellFreeCell::CreateWellFreeCell(
LStream *inStream)
{
return (new WellFreeCell(inStream));
}
// ---------------------------------------------------------------------------
// Ñ WellFreeCell()
// ---------------------------------------------------------------------------
// Default Constructor
WellFreeCell::WellFreeCell()
{
mPaneID = 0;
mFrameSize.width = mFrameSize.height = 0;
mFrameLocation.h = mFrameLocation.v = 0;
mUserCon = 0;
mFrameBinding.left =
mFrameBinding.top =
mFrameBinding.right =
mFrameBinding.bottom = false;
mVisible = mActive = mEnabled = triState_Latent;
mSuperView = nil;
theDoc->theFreeCells[theDoc->currentFreeCell] = this;
theDoc->currentFreeCell++;
itsCard.card = kNoCard;
itsCard.itsOwner = this;
}
// ---------------------------------------------------------------------------
// Ñ WellFreeCell(const WellFreeCell&)
// ---------------------------------------------------------------------------
// Copy Constructor
WellFreeCell::WellFreeCell(
const WellFreeCell &inOriginal)
{
// Copy members of Original
mPaneID = inOriginal.mPaneID;
mFrameSize = inOriginal.mFrameSize;
mFrameLocation = inOriginal.mFrameLocation;
mFrameBinding = inOriginal.mFrameBinding;
mUserCon = inOriginal.mUserCon;
mSuperView = nil; // Copy is not inside any View
// Pane properties. If Original has
// property ON, Copy is Latent.
mVisible = inOriginal.mVisible;
if (mVisible == triState_On) {
mVisible = triState_Latent;
}
mActive = inOriginal.mActive;
if (mActive == triState_On) {
mActive = triState_Latent;
}
mEnabled = inOriginal.mEnabled;
if (mEnabled == triState_On) {
mEnabled = triState_Latent;
}
theDoc->theFreeCells[theDoc->currentFreeCell] = this;
theDoc->currentFreeCell++;
itsCard.card = kNoCard;
itsCard.itsOwner = this;
}
// ---------------------------------------------------------------------------
// Ñ WellFreeCell(SPaneInfo&)
// ---------------------------------------------------------------------------
// Construct Pane from data in a struct
WellFreeCell::WellFreeCell(
const SPaneInfo &inPaneInfo)
{
InitPane(inPaneInfo);
}
// ---------------------------------------------------------------------------
// Ñ WellFreeCell(LStream*)
// ---------------------------------------------------------------------------
// Construct Pane from data in a Stream
WellFreeCell::WellFreeCell(
LStream *inStream)
{
SPaneInfo thePaneInfo;
inStream->ReadData(&thePaneInfo, sizeof(SPaneInfo));
InitPane(thePaneInfo);
}
// ---------------------------------------------------------------------------
// Ñ InitPane
// ---------------------------------------------------------------------------
// Initialize Pane from data in a struct
void
WellFreeCell::InitPane(
const SPaneInfo &inPaneInfo)
{
mPaneID = inPaneInfo.paneID;
mFrameSize.width = inPaneInfo.width;
mFrameSize.height = inPaneInfo.height;
mUserCon = inPaneInfo.userCon;
mVisible = triState_Off;
if (inPaneInfo.visible) {
mVisible = triState_Latent;
}
mActive = triState_Latent;
mEnabled = triState_Off;
if (inPaneInfo.enabled) {
mEnabled = triState_Latent;
}
mFrameBinding = inPaneInfo.bindings;
mSuperView = nil;
LView *theSuperView = inPaneInfo.superView;
if (theSuperView == Default_SuperView) {
theSuperView = GetDefaultView();
}
PutInside(theSuperView);
if (theSuperView != nil) {
PlaceInSuperImageAt(inPaneInfo.left, inPaneInfo.top, false);
Boolean expandHoriz = (inPaneInfo.width < 0);
Boolean expandVert = (inPaneInfo.height < 0);
if (expandHoriz || expandVert) {
theSuperView->ExpandSubPane(this, expandHoriz, expandVert);
}
}
theDoc->theFreeCells[theDoc->currentFreeCell] = this;
theDoc->currentFreeCell++;
itsCard.card = kNoCard;
itsCard.itsOwner = this;
}
// ---------------------------------------------------------------------------
// Ñ ~WellFreeCell
// ---------------------------------------------------------------------------
// Destructor
WellFreeCell::~WellFreeCell()
{
PutInside(nil);
if (sLastPaneClicked == this) {
sLastPaneClicked = nil;
}
}
// ---------------------------------------------------------------------------
// Ñ Draw
// ---------------------------------------------------------------------------
// Try to draw contents of a Pane
//
// inSuperDrawRgnH specifies, in Port coordinates, the portion of the
// Pane's SuperView that needs to be drawn. Specify nil to bypass
// the intersection test.
//
// This is a wrapper function which calls DrawSelf if it is proper for
// the Pane to draw. This means that:
// > Pane's Visible property is on
// > Pane can be focused
// > Pane's Frame is in QuickDraw space
// > Pane's Frame intersects inSuperDrawRgnH
void WellFreeCell::Draw(RgnHandle inSuperDrawRgnH)
{
Rect frame;
if ( IsVisible() &&
FocusDraw() &&
CalcPortFrameRect(frame) &&
((inSuperDrawRgnH == nil) || RectInRgn(&frame, inSuperDrawRgnH)) )
{
if (itsCard.card == kNoCard)
{
EraseRect(&frame);
FrameRoundRect(&frame, 20, 20);
}
else
{
theDeck->DrawCard(&itsCard, frame);
FrameRoundRect(&frame, 20, 20);
}
}
}